home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 182_01 / bbsc.c < prev    next >
Text File  |  1990-07-30  |  29KB  |  1,132 lines

  1. /*
  2.     bbsc.c
  3.  
  4.     BBS (Bulletin Board System) written in UNIX SYSTEM-III "C".
  5.  
  6.         Support files needed:
  7.             bbscdef.h
  8.             bbscport.o or bbscport.c
  9.             bbsclock.o or bbsclock.c
  10.             bbscfile.o or bbscfile.c
  11.             bbscmisc.o or bbscmisc.c
  12.  
  13.                 Mike Kelly
  14.  
  15.     03/09/83 v1.0   written
  16.     07/07/83 v1.0   updated
  17. */
  18. #define MAINMOD 1
  19. #include "bbscdef.h"
  20.  
  21. #define LASTDATE  " 02/07/84 "
  22.  
  23. #define PGMNAME "BBSc    "
  24. #define VERSION " 1.1 "
  25.  
  26.  
  27. main()
  28.     {
  29.     int i;
  30. /*
  31. *       init global variables
  32. */
  33.     debug   = FALSE;
  34.     statcnt = 0;
  35.     xpert   = FALSE;
  36.     active  = TRUE;
  37.  
  38.     w_fname[0] = '\0';
  39.     w_lname[0] = '\0';
  40.     strcpy(w_password,"MPK0");
  41.  
  42.     u_fname[0] = '\0';
  43.     u_lname[0] = '\0';
  44.     strcpy(u_password,"MPK0");
  45.     u_time1[0] = '\0';
  46.     u_date1[0] = '\0';
  47.     u_time2[0] = '\0';
  48.     u_date2[0] = '\0';
  49.     u_city[0]  = '\0';
  50.  
  51.     mm[0]    = '\0';
  52.     dd[0]    = '\0';
  53.     yy[0]    = '\0';
  54.     month[0] = '\0';
  55.     day[0]   = '\0';
  56.     year[0]  = '\0';
  57.     date[0]  = '\0';
  58.     week[0]  = '\0';
  59.     ttime[0] = '\0';
  60.  
  61.     strcpy(msg_delete,"0");
  62.     msg_no[0]   = '\0';
  63.     msg_date[0] = '\0';
  64.     msg_date[0] = '\0';
  65.     msg_time[0] = '\0';
  66.     msg_to[0]   = '\0';
  67.     msg_from[0] = '\0';
  68.     msg_pass[0] = '\0';
  69.     msg_subject[0] = '\0';
  70.     msg_text[0] = '\0';
  71.  
  72.     stop_that = FALSE;
  73.  
  74. /*   get date and time from the clock   */
  75.  
  76.     gettime(ttime);
  77.     getdate(mm,dd,yy,month,day,year,date,week);
  78.  
  79.     portinit() ;    /* init terminal modes */
  80.     signon()   ;
  81.     driver()   ;
  82.     portrst()  ;    /* undo any special modes */        
  83.     }
  84. /*  end of mainline routine     */
  85.  
  86. driver()
  87.     {
  88. char    linebuf[MAXLINE],
  89.     buf[128],
  90.     *bufptr,        /* ptr to buf */
  91.     usercd[100],        /* user record */
  92.     *userptr,       /* ptr to usercd */
  93.     cmd[2];
  94.  
  95. int cnt,
  96.     ok_sw,
  97.     case_sw,
  98.     i,
  99.     num0,
  100.     num1,
  101.     num2;
  102.  
  103.     cnt = 0;
  104.     ok_sw   = TRUE;
  105.     bufptr  = buf;
  106.     xpert   = FALSE;
  107.     cmd[0]  = '\0';
  108.  
  109.     while (active)
  110.         {
  111.         stop_that = FALSE ;     /* reset switch */
  112.         portsout(CRLF);
  113.         if (!xpert)
  114.             {
  115.             portsout("Commands: B,C,E,G,K,N,Q,R,S,W,X or ? ");
  116.             }
  117.         portsout("===> ");
  118.         portsin(cmd,1);
  119.         portsout(CRLF);
  120.  
  121.         *cmd = toupper(*cmd) ;
  122.  
  123.         switch (cmd[0])
  124.             {
  125.             case ('C'):     /* Unix */
  126.                 cmd_c();
  127.                 break;
  128.             case ('E'):     /* enter msg */
  129.                 cmd_e();
  130.                 break;
  131.             case ('G'):     /* goodby */
  132.                 cmd_g();
  133.                 break;
  134.             case ('K'):     /* kill msg */
  135.                 cmd_k();
  136.                 break;
  137.             case ('Q'):     /* quick scan */
  138.                 cmd_q();
  139.                 break;
  140.             case ('R'):     /* read msg */
  141.                 cmd_r();
  142.                 break;
  143.             case ('S'):     /* scan msg */
  144.                 cmd_s();
  145.                 break;
  146.             case ('X'):     /* expert toggle */
  147.                 cmd_x();
  148.                 break;
  149.             case ('N'):     /* print new-user stuff */
  150.                 cmd_p(NEWUSER);
  151.                 break;
  152.             case ('W'):     /* print welcome file */
  153.                 cmd_p(WELCOME);
  154.                 break;
  155.             case ('B'):     /* print bulletins */
  156.                 cmd_p(BULLETINS);
  157.                 break;
  158.             case ('?'):     /* help */
  159.                 cmd_p(HELP);
  160.                 break;
  161.             default:
  162.                 break;
  163.             }
  164.  
  165.         }
  166.     }
  167. /*  end of function     */
  168.  
  169. cmd_g()         /* good-by */
  170.     {
  171.     active = FALSE;
  172.     portsout("\r\nThanks for calling ");
  173.     portsout(w_fname) ;
  174.     portsout(CRLF)    ;
  175.     sleep(5)          ;     /* for the Smartmodem */
  176.     portsout("+")     ;     /* get the modems attention */
  177.     portsout("+")     ;     /* get the modems attention */
  178.     portsout("+")     ;     /* get the modems attention */
  179.     sleep(15)         ;         /* for the Smartmodem */
  180.     gobble()          ;
  181.     portsout("ATH")   ;     /* hang up the phone */
  182.     portsout(CRLF)    ;
  183.     sleep(15)         ;         /* for the Smartmodem */
  184.     }
  185. /*  end of function     */
  186.  
  187. cmd_c()         /* go to the operating system level */
  188.     {
  189.     if ((inbuf=fopen(SYSTEM,"r")) == NULL)
  190.         {
  191.         portsout(CRLF) ;
  192.         portsout("Exiting to the operating system level!") ;
  193.         portsout(CRLF) ;
  194.         }
  195.     else
  196.         {
  197.         porttype(inbuf);    /* type a file to port */
  198.         close(inbuf);
  199.         }
  200.     active = FALSE;
  201.     }
  202. /*  end of function     */
  203.  
  204. cmd_e()         /* enter a message */
  205.     {
  206.     int entering,
  207.         editing,
  208.         cnt1;
  209.     char    msg[50],
  210.         l_cnt[3],
  211.         ans[2];
  212.  
  213.     entering = editing = TRUE;
  214.     cnt1 = 0;
  215.     l_cnt[0] = '0';         /* init line count */
  216.     msg_text[0] = '\0';     /* init message text area */
  217.  
  218.     portsout(CRLF);
  219.     portsout("This will be message # ");
  220.     portsout(h_next_msg);
  221.     portsout(CRLF);
  222.     portsout("                             ____.____1____.____2\r\n");
  223.     portsout("Who is the message for  ===> ");
  224.     portsin(msg_to,20);
  225.     portsout(CRLF);
  226.     portsout("What is the subject     ===> ");
  227.     portsin(msg_subject,20);
  228.     portsout(CRLF);
  229.  
  230.     portsout(CRLF) ;
  231.     portsout("A line can contain 40 characters, up to 20 lines.") ;
  232.     portsout(CRLF) ;
  233.     portsout("To end, enter a carriage return on an empty line.") ;
  234.     portsout(CRLF) ;
  235.     portsout(CRLF) ;
  236.     portsout("    .___.____1____.____2____.____3____.____4") ;
  237.     portsout(CRLF) ;
  238.  
  239.     while (entering)        /* get the text of the message */
  240.         {
  241.         linecnt(l_cnt);     /* calc line count */
  242.  
  243.         portsout(l_cnt);    /* show line count */
  244.         portsout("> ");     /*  and prompt */
  245.  
  246.         portsin(msg,40);
  247.         portsout(CRLF);
  248.  
  249.         strcat(msg,"\n");   /* put a <lf> on each line */
  250.  
  251.         if (strlen(msg) < 2)        /* count cr too */
  252.             {
  253.             entering = FALSE;   /* all done */
  254.             }
  255.         else
  256.             {
  257.             strcat(msg_text,msg);   /* append each line to text */
  258.             }
  259.         if ((++cnt1) > 19)      /* only allow 20 lines */
  260.             {
  261.             entering = FALSE;   /* all done */
  262.             }
  263.         }
  264.  
  265.     while (editing)     /* save it, fix it, list it, or get out */
  266.         {
  267.         portsout(CRLF);
  268.         portsout("(S)ave,   (L)ist,   or (Q)uit") ;
  269.         portsout(CRLF);
  270.         portsout("(D)elete, (I)nsert, or (E)dit line ==> ") ;
  271.         portsin(ans,1);         /* get a byte */ 
  272.         portsout(CRLF);
  273.  
  274.         *ans = toupper(*ans) ;
  275.  
  276.         switch (ans[0])         /* get 1 byte */
  277.             {
  278.             case ('S'):     /* save message */
  279.                 savemsg();
  280.                 editing = FALSE; /* get out of while */
  281.                 break;
  282.             case ('E'):     /* edit message */
  283.             case ('I'):     /* edit message */
  284.             case ('D'):     /* edit message */
  285.                 editmsg(*ans);
  286.                 break;
  287.             case ('L'):     /* list message */
  288.                 listmsg();
  289.                 break;
  290.             case ('Q'):     /* get out w/out saving */
  291.                 editing = FALSE; /* get out of while */
  292.                 break;
  293.             default:
  294.                 portsout(CRLF);
  295.                 portsout("Shall we try that one again?\r\n");
  296.                 break;
  297.             }   
  298.         }
  299.  
  300.     }
  301. /*  end of function     */
  302.  
  303. linecnt(lcnt)           /* 2 byte string of line numbers */
  304. char    *lcnt;
  305.     {
  306.     int icnt;
  307.     char    xcnt[4];
  308.  
  309.     icnt = atoi(lcnt);
  310.     if (++icnt < 10)
  311.         {
  312.         strcpy(lcnt,"0");
  313.         itoa(xcnt,icnt);
  314.         strcat(lcnt,xcnt);
  315.         }
  316.     else
  317.         {
  318.         itoa(xcnt,icnt);
  319.         strcpy(lcnt,xcnt);
  320.         }
  321.     return;
  322.     }
  323. /*